package algorithm.class2;

import algorithm.ArrUtil;

/**
 * 等概率问题
 */
public class _06EqualProbabilityRandom {

    /**
     * 固定概率返回0或1
     *
     * @return
     */
    public static int f() {
        return Math.random() < 0.8 ? 0 : 1;
    }

    /**
     * 0，1发生器(等概率返回0或1)
     */
    private static int f1() {
        int i = 0;
        do {
            i = f();
        } while (i == f());
        return i;
    }

    public static void main(String[] args) {
        int times = 1000000;
        int[] results = new int[2];
        for (int i = 0; i < times; i++) {
            results[f1()]++;
        }
		ArrUtil.print(results);
    }

}
